package com.hk.dao.impl;

import com.hk.dao.IAdminDao;
import com.hk.model.Admin;
import com.hk.utils.JdbcMysql;
import com.hk.utils.SqlSymbol;

import java.sql.ResultSet;

/**
 * @Author: zhe
 * @Date: 2021/6/5 18:25
 * @Statement: 管理员持久层
 */
public class AdminDaoImpl implements IAdminDao {

//    JDBC连接工具类
    private static JdbcMysql jdbcMysql = JdbcMysql.getInstance();

    private static String sql = "";

    /**
     * 返回查询到的数据
     * @param admin
     * @return
     */
    @Override
    public ResultSet findByEmailAndPassword(Admin admin) {
        sql = "select * from admin where email = "+
                SqlSymbol.MARK.getValue() +admin.getEmail()+SqlSymbol.MARK.getValue()+
                " and "+" password = "+
                SqlSymbol.MARK.getValue()+admin.getPassword()+SqlSymbol.MARK.getValue()+
                " and state = "+0;
        ResultSet resultSet = jdbcMysql.jdbcQuery(sql);
        return resultSet;
    }

    @Override
    public ResultSet findByEmail(String email) {
        sql = "select * from admin where email = "+SqlSymbol.MARK.getValue()+email+SqlSymbol.MARK.getValue();
        ResultSet resultSet = jdbcMysql.jdbcQuery(sql);
        return resultSet;
    }

    @Override
    public ResultSet findAll(Integer page, Integer limit, Admin t) {
        return null;
    }

    @Override
    public ResultSet count(Integer page, Integer limit, Admin t) {
        return null;
    }

    @Override
    public ResultSet findById(Integer id) {
        sql = "select * from admin where id = "+id;
        ResultSet resultSet = jdbcMysql.jdbcQuery(sql);
        return resultSet;
    }

    @Override
    public int save(Admin admin) {
        return 0;
    }

    @Override
    public int update(Admin admin) {
        sql = "update admin set " +
                "name = "+SqlSymbol.MARK.getValue()+admin.getName()+SqlSymbol.MARK.getValue()+SqlSymbol.COMMA.getValue()+
                "sex = "+admin.getSex()+SqlSymbol.COMMA.getValue()+
                "birthday = "+SqlSymbol.MARK.getValue()+admin.getBirthday()+SqlSymbol.MARK.getValue()+SqlSymbol.COMMA.getValue()+
                "phone = "+SqlSymbol.MARK.getValue()+admin.getPhone()+SqlSymbol.MARK.getValue()+SqlSymbol.COMMA.getValue()+
                "site = "+SqlSymbol.MARK.getValue()+admin.getSite()+SqlSymbol.MARK.getValue()+SqlSymbol.COMMA.getValue()+
                "gmt_modified = "+SqlSymbol.MARK.getValue()+admin.getGmtModified()+SqlSymbol.MARK.getValue()+
                " where id = "+admin.getId();
        int i = jdbcMysql.jdbcUpdate(sql);
        return i;
    }

    @Override
    public int updatePassWord(Admin admin) {
        sql = "update admin set " +
                "password = "+SqlSymbol.MARK.getValue()+admin.getPassword()+SqlSymbol.MARK.getValue()+SqlSymbol.COMMA.getValue()+
                "gmt_modified = "+SqlSymbol.MARK.getValue()+admin.getGmtModified()+SqlSymbol.MARK.getValue()+
                " where id = "+admin.getId();
        int i = jdbcMysql.jdbcUpdate(sql);
        return i;
    }

    @Override
    public int delete(Integer id) {
        return 0;
    }
}
